﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Student/Views/Shared/_Layout.cshtml";
}
<div id="divMsgIndex" class="popup_error"></div>
<div id="varify" style="display: none">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="well span20 center login-box">
                <form action="../Student/home/ActivationMail">
                    <div class="alert alert-info" id="reg">
                        <span id="scmsg"></span>
                    </div>
                    <div class="alert alert-info">
                        <p>Please Check Your MailBox , </p>
                        <p>And Complete the Process of Varification</p>
                    </div>
                    <div>
                        <button title="Resend" id="btnresend" class="btn btn-primary" onclick="resend();">Resend Mail</button>
                        <div>In case of Mail not Received or Deleted</div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="widget">
    <div class="widget-head">OverAll Performance of Test</div>
    <div class="widget-content">
        <div class="padd">
            <div id="divMsgIndex2"></div>
            <canvas id="ChartStudent" height="300" width="1024"></canvas>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-lg-6">
        <div class="widget">
            <div class="widget-head">Test Attempt Ratio</div>
            <div class="widget-content">
                <div class="padd">
                     <div id="divMsgIndex1"></div>
                    <canvas id="pie1" height="250" width="400"></canvas>
                </div>
            </div>
        </div>
    </div>
</div>
@section scripts{
    <script type="text/javascript">
        function vall() {
            return (Math.floor(Math.random() * 156) + 50).toString();
        }
        function rgba() {
            return 'rgba(' + vall() + ',' + vall() + ',' + vall() +','+0.9+ ')';
        }
        function createChart() {
          
            var cht = document.getElementById('ChartStudent');
            var ctx = cht.getContext('2d');
            $.ajax({
                url: "/Student/Home/BarDataTest",
                type: "POST",
                success: function (data) {
                    // For Bar Control Data Binding 
                    var data1 = {
                        "datasets":
                            [{
                                fillColor: "rgba(26,174,243,0.6)",
                                strokeColor: "rgba(151,187,205,0.5)",
                                highlightFill: "rgba(9,147,211,0.9)",
                                highlightStroke: "rgba(151,187,205,1)",
                                data: data.datasets.data
                            }],
                        labels: data.labels
                    }
                    var barChart = new Chart(ctx).Bar(data1, {
                      			responsive: true
                       		});
                    //End Bar Control Data Binding
                },
                error: function (data) {
                }
            });
            var cht1 = document.getElementById('pie1');
            var ctx1 = cht1.getContext('2d');
            var myPieChart1 = new Chart(ctx1).Pie();
            $.ajax({
                url: "/Student/Home/BarDataAttempt",
                type: "POST",
                success: function (data) {
                    if (data.dataobj2.length != 0) {
                        for (var i = 0; i < data.dataobj2.length; i++) {
                            var col = rgba();
                            var colnew = col.replace(/0.9/i, "0.7");
                            myPieChart1.addData({
                                value: Math.round(data.dataobj2[i].Average),
                                color: col,
                                highlight: colnew,
                                label: data.dataobj2[i].TestName
                            });
                            $("#pie1").show();
                            $("#ChartStudent").show();
                            $("#divMsgIndex1").hide();
                            $("#divMsgIndex2").hide();
                        }
                    }
                    else {
                        showMsg('divMsgIndex1', '<b>Data Not Available</b>', 'info');
                        showMsg('divMsgIndex2', '<b>Data Not Available</b>', 'info');
                        $("#pie1").hide();
                        $("#ChartStudent").hide();
                    }
                },
                error: function (data) {
                }
            });
        }
        $(document).ready(function () {
            createChart();
            var msg = '@Session["sc"]'
            if (msg.length > 3) {
                $("#scmsg").text('@Session["sc"]');
            }
            else {
                $("#reg").hide();
            }
            $('#h2Title').html("<i class='fa fa-home'></i> Dashboard");
            $('#aTitle').html("Dashboard");
            $('#liDashboard').addClass("open");
            var notice = '@TempData["notice"]';
            if (notice.length > 1) {
                showMsg('divMsgIndex', notice, 'success');
                $('#divMsgIndex').css({ "display": "block" });
            }
            else {
                $('#notice').hide();
            }
            varify();
            function varify() {
                $.getJSON("/Student/Home/Isvarify", { dt: "test" },
                function (cnt) {
                    if (cnt != null && cnt == 1) {
                        $("#varify").css({ "display": "Block" });
                    }
                });
            }
            function resend() {
                $.getJSON("/Student/Home/ActivationMail", { dt: "test" },
                function (st) {
                    if (st != null && st == 1) {
                    }
                });
            }
        });
    </script>
}
